/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = wtc_wsrpcrq.c                                      */
/*  NOTE      =                                                    */
/*  DATE      = 2015/08/26 by songbb                               */
/*******************************************************************/

#include "frreport_comm.h"

#include "../wtc_core.h"
#include "../wtc_comm.h"
#include "../wtc_mar.h"
#include "wtc_wsrpcrq.h"

int wtc_wsrpcrq_postrecv_wsrpcrq(L7_wtc_packet *p_st_wtc_packet
                                , int i_recv_size)
{
    return bytebuff_skip(p_st_wtc_packet->p_st_packet, (size_t) i_recv_size);
}

int wtc_wsrpcrq_postrecv_wsinit_rp(L7_wtc_packet *p_st_wtc_packet
                                , int i_recv_size)
{
    return bytebuff_skip(p_st_wtc_packet->p_st_packet, (size_t) i_recv_size);
}

int wtc_wsrpcrq_tmpostrecv(Conntrack *p_st_conn
                        , L7session_wtc *p_st_sess
                        , L7_wtc_packet *p_st_wtc_packet
                        , int i_recv_size
                        , Frreport_body_data *p_st_body)
{
    WTC_PRINT_INFO("wtc_wsrpcrq_tmpostrecv...\n");
    unsigned int ui_descrim = 0;
    int i_type = 0;

    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_descrim, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;

    i_recv_size -= 4;
    switch (ui_descrim)
    {
        case 8:
            i_type = 0;
            break;
        case 1:
            i_type = 1;
            break;
        default:
            goto error;
    }

    if (i_type == 0)
    {
        if (wtc_wsrpcrq_postrecv_wsrpcrq(p_st_wtc_packet, i_recv_size) != FR_SUCC)
            goto error;
    }
    else
    {
        if (wtc_wsrpcrq_postrecv_wsinit_rp(p_st_wtc_packet, i_recv_size) != FR_SUCC)
            goto error;
    }

    return FR_SUCC;
error:
    return FR_FAIL;
}

//////////////////////// for analyze direction
int wtc_wsrpcrq_tmpostrecv_fad(int i_recv_size
                            , char *p_payload
                            , unsigned int ui_payload_len
                            , unsigned int *p_ui_offset)
{
    unsigned int ui_descrim = 0;

    if (wtc_get_int(p_payload, ui_payload_len, p_ui_offset, &ui_descrim) != FR_SUCC)
        goto error;

    i_recv_size -= 4;
    switch (ui_descrim)
    {
        case 8:
        case 1:
            break;
        default:
            goto error;
    }

    if (wtc_skip(p_payload, ui_payload_len, p_ui_offset, i_recv_size) != FR_SUCC)
        goto error;

    return FR_SUCC;
error:
    return FR_FAIL;
}
